# encoding: utf-8

import pyautogui
import pyperclip
import keyboard
import time

class KeyBoardUtil:
    def __init__(self):
        pass

    @classmethod
    def inputText(cls,x,y,text,speed=0.25,hotkey=''):
        try:
            pyautogui.click(x, y)
            pyautogui.write(text, interval=speed)  # 打印书hellow world 每个字符后延迟0.25秒
            if hotkey == "enter":
                pyautogui.press('enter')  # 按下并释放enter
        except:
            pass

    @classmethod
    def click(cls,x,y):
        try:
            pyautogui.click(x, y)
        except:
            pass

    @classmethod
    def inputChnText(cls,x,y,text):
        try:
            pyautogui.click(x, y)
            pyautogui.hotkey('Ctrl', 'a')
            pyperclip.copy(text)
            pyautogui.hotkey('Ctrl', 'v')
        except:
            pass

    @classmethod
    def inputSimpleChnText(cls,x,y,text):
        try:
            pyautogui.click(x, y)
            pyperclip.copy(text)
            pyautogui.hotkey('Ctrl', 'v')
        except:
            pass

    @classmethod
    def inputCopyChnText(cls,text):
        try:
            pyperclip.copy(text)
            pyautogui.hotkey('Ctrl', 'v')
        except:
            pass

    @classmethod
    def inputTextDirect(cls,text,speed=0.25,hotkey='enter'):
        try:
            pyautogui.write(text, interval=speed)
            if hotkey == "enter":
                pyautogui.press('enter')  # 按下并释放enter
        except:
            pass

    @classmethod
    def oneHot(cls, key):
        try:
            pyautogui.hotkey(key)
        except:
            pass

    @classmethod
    def twoHot(cls, key, helpkey):
        try:
            pyautogui.hotkey(key, helpkey)
        except:
            pass

    @classmethod
    def keyboardInput(cls,text,hot="enter"):
        keyboard.write(text)
        time.sleep(2)
        if hot == "enter":
            keyboard.send('enter')

    @classmethod
    def keyboardInputOnly(cls,text):
        keyboard.write(text)

    @classmethod
    def keyboardEnter(cls):
        keyboard.send('enter')